<!--
  ~ Copyright 2016 Red Hat, Inc. and/or its affiliates
  ~ and other contributors as indicated by the @author tags.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
        >
    <body>
        <h1>Third Party App That Pulls Data Using OAuth</h1>
        <h:form>
            #{userData.accessTokenAvailabilityMessage}
            <br />
            <h:commandButton id="retrieve_token" value="Retrieve/refresh access token" action="#{databaseClient.retrieveAccessToken}"/>
            <h:commandButton id="products_request" value="Load products list" action="#{databaseClient.sendProductsRequest}"/>
            <h:commandButton id="customers_request" value="Load customers list" action="#{databaseClient.sendCustomersRequest}"/>
        </h:form>

        <ui:fragment rendered="#{userData.hasProducts}">
            <hr />
            <h3>Products data available</h3>
            <ui:repeat value="#{userData.products}" var="product">
                #{product}<br/>
            </ui:repeat>
        </ui:fragment>

        <ui:fragment rendered="#{userData.hasCustomers}">
            <hr />
            <h3>Customers data available</h3>
            <ui:repeat value="#{userData.customers}" var="customer">
                #{customer}<br/>
            </ui:repeat>
        </ui:fragment>

        <div style="color: red">
            #{messagesChecker.checkMessage}
            <h:messages globalOnly="true"/>
        </div>
    </body>
</html>
